package com.itchu.customer;

import com.itchu.common.domain.PageResult;
import com.itchu.system.domain.Singer;
import com.itchu.system.domain.Song;
import com.itchu.system.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/api/singer")
public class vSingerController {

    @Autowired
    private SingerService singerService;

    /**
     * 查找歌手的分页信息
     * @param key   搜索条件
     * @param page  当前页
     * @param rows  页大小
     * @param sortBy
     * @param desc
     * @return
     */
    @GetMapping("/page")
    public ResponseEntity<PageResult<Singer>> findByPage(
            @RequestParam(value = "key", required = false) String key,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "20") Integer rows,
            @RequestParam(value = "sortBy", required = false) String sortBy,
            @RequestParam(value = "desc", required = false) Boolean desc
    ) {
        PageResult<Singer> list = singerService.findByPage(key,page,rows,sortBy,desc);
        return ResponseEntity.ok(list);
    }

    /**
     * 根据歌手id查出所有歌曲
     * @param id  歌手id
     * @return
     */
    @GetMapping("/of/listSongs")
    public ResponseEntity<List<Song>> findSongsBySingerId(
            @RequestParam(value = "id") Long id
    ) {
        List<Song> list = singerService.findSongsBySingerId(id);
        return ResponseEntity.ok(list);
    }

    /**
     * 按名字做模糊搜索
     * @param name
     * @return
     */
    @GetMapping("search/Singers")
    public ResponseEntity<List<Singer>> searchSingersByName(
            @RequestParam(value = "name") String name
    ) {
        List<Singer> list = singerService.searchSingersByName(name);

        return ResponseEntity.ok(list);
    }

    /**
     * -------------------------
     * 查找所有歌手
     * @return
     */
    @GetMapping("/all")
    public ResponseEntity<List<Singer>> findAll() {
        List<Singer> list = singerService.findAll();
        return ResponseEntity.ok(list);
    }
}
